#include "AI.h"

extern map<string,int> number_map;
extern map<string,int>::iterator number_it;

extern list<string> num_alpha_list;
extern list<string>::iterator num_alpha_it;

int EnglishNum()
{
	bool exponentFlag = false;
	bool oneFlag = false;

	int ret = 0;
	int hundred = 0;
	int ten = 0;
	int one = 0;

	for(num_alpha_it=num_alpha_list.begin(); num_alpha_it!=num_alpha_list.end();num_alpha_it++)
	{
		if(number_map[*num_alpha_it] < 10)
		{
			one = number_map[*num_alpha_it];

			exponentFlag = true;
			oneFlag = true;
		}

		else if(number_map[*num_alpha_it] < 100)
		{
			ten = number_map[*num_alpha_it];

			exponentFlag = true;
		}

		else if(number_map[*num_alpha_it] == 100)
		{
			if(oneFlag)
			{
				hundred = one * 100;
				one = 0;
			}

			else
			{
				hundred = 100;
			}

			exponentFlag = true;

			oneFlag = false;
		}

		else
		{
			if(exponentFlag)
			{
				ret += (hundred + ten + one) * number_map[*num_alpha_it];

				exponentFlag = false;
				oneFlag = false;

				hundred = 0;
				ten = 0;
				one = 0;
			}

			else
			{
				ret += number_map[*num_alpha_it];
			}
		}
	}

	if(exponentFlag)
	{
		ret += hundred + ten + one;
	}

	return ret;
}